/* -------------------------------------------------------------------
 * event.h
 *
 * typedefs for the event table structure
 * ------------------------------------------------------------------ */


#define EVENTTABLESIZE 1024*8	//32
#define NUMPLAYERWEAPONS 5
#define NULL 0
#define NUMSCENES 12 //17

#define MAXFIRES	  10 /*Maximum number of times enemy fires*/
#define MAXCLASSES    32
#define MAXTARGETS    400
#define MAXENEMYSHOTS 16
#define MAXCYBWEAPONS 6  /*Weapons + upgrades*/

//Sprite states
#define STATE_DEAD   0x8888
#define STATE_REST   0x1111
#define STATE_ALIVE  0x2222
#define STATE_SLEEP  0x3333

//Sprite types
#define TARGET_CLUE  'clue'
#define TARGET_WEAP  'weap'
#define TARGET_TOOL  'tool'
#define TARGET_ENEMY 'enem'

#define TARGET      struct s_target
#define TARGETCLASS struct s_targetclass

#define TARGETSTATUS struct s_targetstatus
TARGETSTATUS 
{
    //This information changes as the game progesses
	long	life;		    /* how much damage can this target sustain */
	short	state;          /* Enemy is alive,dead or asleep*/
	long    isonscreen;     /*Sprite is or is not on the screen*/
	short	explosioncount;	/* what frame of the explosion animation 
	                           is this enemy on */
	short	explosionsize;	/* The size of this explosion*/
};

TARGET
{
	TARGETSTATUS  status;   /*Status of the target within the game*/
   long    startframe;     /* Frame enemy appears on*/
	long    endframe;       /* Frame enemy ends on*/
	long	type;			/* The type of the target*/
	long	id;				/* The id of the target*/
	long	targettype;		/* The target type of the target*/
	long	toolweapclue;	/* The tool,clue or weapon number of the target, if one*/
	short	channel;	    /* what channel the enemy is in */ 
	short	eclass;         /* pointer to proper class*/

   char    targetable;     /*Whether or not the enemy is target able*/
	char    numfires;		   /*Number of times enemy fires*/
	long    fframes[MAXFIRES]; /*Fire frames*/
	TARGET *onscreen;       /*Used for the on screen list*/
	TARGET *linked;			/*Used for the LINK list*/
	TARGET *linkhead;		/*Used for the LINK list*/
#if 1 
	short	bracketcount;	/* what frame of the bracket animation 
	                           is this enemy on*/
	short bracketred;
	long	bracketwidth;	/* width of the last bracket that was drawn*/
	long	bracketheight;	/* height of the last bracket that was drawn*/
#endif
};


TARGETCLASS
{
	long	type;			/* 4 characters used for matching id's */
	long	damage;			/* how much damage is done per hit */
	long	hitpoints;		/* how much total damage can this type take */
	long  pdamage[MAXCYBWEAPONS]; /*Damage each of the players weapons does to this target*/
};

typedef struct
{
 	long sframe;
	long type;
	long lastframe;
	long channel;
	long cluefile;
	long id;
} clueevent;

typedef struct
{
 	long sframe;
	long type;
	long lastframe;
	long channel;
	long id;
} weapevent;

typedef struct
{
	long sframe;
	long type;
	long lastframe;
	long channel;
	long id;
	long weaptool;
} toolevent;

typedef struct
{
	long sframe;
	long type;
	long channel;
} shotevent;


typedef struct
{
	long	inuse;
	long	damage;	/* damage shot will do */
	short	x,y;		/* Coords of shot on screen */
	short dx,dy;	/* Vector of shot */
} enemyshot;


typedef struct
{
	long	sframe;
	long 	type;
	long 	scene;
	long 	frame;
} deathBranch;

typedef struct
{
 	long		sframe;
	long		type;
	long		scene;
	long		frame;
	long		videoid;
} videoPlay;

#ifdef _EVENT_
long	g_numclasses = -1;
long	g_numtargets = -1;

#define CUTS    struct s_cuts
#define CUTSON  struct s_cutsceneon
#define CUTSOFF struct s_cutsceneoff
#define CLAS    struct s_clas
#define CTAR    struct s_ctar
#define COND    struct s_cond
#define ACLU    struct s_aclu
#define SCLU    struct s_sclu
#define AUDI    struct s_audi
#define VIEW    struct s_view
#define FIRE    struct s_fire
#define DAMG    struct s_damg
#define ECLUE   struct s_eclue
#define ETOOL   struct s_etool
#define EWEAP   struct s_eweap
#define STAR    struct s_star
#define CONT    struct s_cont
#define LINK    struct s_link
#define BRAN    struct s_bran
#define WBRN    struct s_wbrn
#define WSCN    struct s_wscn
#define DBRN    struct s_dbrn
#define CBRN    struct s_cbrn
#define EXIT    struct s_exit
#define ESCN    struct s_escn
#define DOZE    struct s_doze
#define TGON    struct s_tgon
#define TGOF    struct s_tgof
#define DETH    struct s_deth
#define LEAV    struct s_leav
#define ECUT    struct s_ecut
#define JUMP    struct s_jump
#define VIDI    struct s_vidi
#define WEAP    struct s_weaptool
#define TOOL    struct s_weaptool

VIDI
{
  long vidinumber;
};

JUMP
{
  long jumpframe;
};

DETH
{
  long deathstart;
};

LEAV
{
  long leavdummy;  //Only here cause the event compiler wont accept
                   //events with no parameters.
};

ESCN
{
  long nextscene;
};

ECUT
{
  long exitstart;
};

VIEW
{
  long view;
};

CUTS
{
  long endframe;
};

CLAS
 {
  long tartype;    /*The enemy target class type, plane, tank, etc*/
  long cdamage;    /*Damage this ememies weapon does to player*/
  long hitpnts;    /*Amount of damage this enemy can take*/
  long pdamage[MAXCYBWEAPONS];
                  /*Amount of damage each of the players weapons does
				    to this enemy.
				   */
 };
 
LINK
 {
  long channel;
  long lchannel;
 };

ACLU
{
	long		sound;
	long		playtimes; // how many times to play the clue as you pass it
};

SCLU
{
	long		sound;  // actually, the scene specific clue file number
};

AUDI
{
	long		sound;
	long		id;
};

ECLUE
 {
  long channel;
  long clueref; /*Offset into cluenames*/
 };

ETOOL
 {
  long channel;
  long toolref; /*Offset into toolnames*/
 };
 
EWEAP
 {
  long channel;
  long weapref; /*Offset into weapon names*/
 }; 
 
FIRE
 {
  long channel;
 };

CBRN
 {
	long 	scene;
	long 	frame;
 };

DBRN
 {
	long 	scene;
	long 	frame;
 };

BRAN
 {
	long		left,upper,right,lower;	/* Area to be in to take branch */
	long		frame;      	/*New frame to seek to*/
 };

CTAR
 {
  long endframe;
  long channel;
  long tartype;
  long id;
 };

TOOL //or WEAP 
 {
  long endframe;
  long channel;
  long tartype;
  long weaptool; //The number of the weapon or tool. index into g_tools/g_weaps
  long id;
 };

COND
 {
  long endframe;
  long channel;
  long tartype;
  long id;
  long condnum;
 };

WSCN
 {
  long wscn; //Scene warning
 };

WBRN
 {
  long wbrn; //Branch warning
 };

CUTSON
 {
  long cuton;
 };

CUTSOFF
 {
  long cutoff;
 }; 
 
EXIT
 {
  long cutplay;
  long nextscene;
 };
 
DOZE
 {
  long channel;
 };

/*Globals*/
long g_clues[NUMSCENES][24];
int g_deadtarget[NUMSCENES][128];
long g_varscene=-2;

/*Functions*/
//void loadevents(char *name);
void   loadevents(void);
void   processevent(long frame);

u8 g_firstcut=0;
long g_cutplay=-1;
char g_branchwarn = 0;
void *g_eventmemory;
void *g_eventfilememory;
void *g_eventframememory;

void *GetEventMemory(long amtreq);
void *GetEventFileMemory(long amtreq);
void *GetEventFrameMemory(long amtreq);

#else
/*Globals*/
extern char g_branchwarn;
extern long g_varscene;
extern int g_deadtarget[NUMSCENES][128];
extern int inCutScene;
extern u8 g_firstcut;
extern long	g_numclasses;
extern long	g_numtargets;
extern long g_cutplay;
extern void *g_eventmemory;
extern void *g_eventfilememory;
extern void processSpecialClue(long clue);
extern void loadevents(void);
extern void processevent(long frame);
extern void initenemyshots();
extern void reseteventtable();
extern void updateEnemyShots(u8 *buffer);
extern void *GetEventMemory(long amtreq);
extern void *GetEventFileMemory(long amtreq);
extern void *GetEventFrameMemory(long amtreq);
#endif
